package classesInterface;

import classesBancodeDados.AssistenteSocial;
import classesBancodeDados.AuxiliarEnfermagem;
import classesBancodeDados.Diretor;
import classesBancodeDados.Enfermeiro;
import classesMiolo.Validador;
import classesBancodeDados.Medico;
import classesBancodeDados.Nutricionista;
import classesBancodeDados.Psicologo;
import classesBancodeDados.Recepcionista;
import classesBancodeDados.TecnicoEnfermagem;
import classesJpa.AssistenteSocialJpaController;
import classesJpa.AuxiliarEnfermagemJpaController;
import classesJpa.DiretorJpaController;
import classesJpa.EnfermeiroJpaController;
import classesJpa.MedicoJpaController;
import classesJpa.NutricionistaJpaController;
import classesJpa.PsicologoJpaController;
import classesJpa.RecepcionistaJpaController;
import classesJpa.TecnicoEnfermagemJpaController;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class JanelaCadastroFuncionario extends javax.swing.JFrame {

    /**
     * Creates new form Cadastro
     */
    private JanelaCadastroFuncionario() {
        initComponents();
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
    
    public static JanelaCadastroFuncionario getInstance(){
        if(instance == null) instance = new JanelaCadastroFuncionario();
        return instance;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDesktopPane1 = new javax.swing.JDesktopPane();
        jSlider1 = new javax.swing.JSlider();
        cadCampoTelefone1 = new javax.swing.JTextField();
        cadCampoDDD1 = new javax.swing.JTextField();
        cadCampoNome = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        cadLabelSobrenome = new javax.swing.JLabel();
        cadLabelNome = new javax.swing.JLabel();
        cadCampoMes = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        cadCampoDia = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        cadCombo = new javax.swing.JComboBox();
        cadCampoSobrenome = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        cadLabelNascimento = new javax.swing.JLabel();
        cadLabel = new javax.swing.JLabel();
        medLabelFormato1 = new javax.swing.JLabel();
        cadComboEstado = new javax.swing.JComboBox();
        cadCampoAno = new javax.swing.JTextField();
        cadCampoCidade = new javax.swing.JTextField();
        cadCampoCPF = new javax.swing.JTextField();
        medLabelCPF1 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        cadCampoEndereco = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        cadLabelVariavel = new javax.swing.JLabel();
        cadCampoVariable = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        cadLabelTipo = new javax.swing.JLabel();
        medBotaoCadastrar1 = new javax.swing.JButton();
        medBotaoLimpar1 = new javax.swing.JButton();
        cadCampoDDD2 = new javax.swing.JTextField();
        cadCampoTelefone2 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        campoLogin = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        campoSenha = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        campoConfSenha = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        cadCampoTelefone1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadCampoTelefone1ActionPerformed(evt);
            }
        });

        jLabel12.setText("Telefone 1:");

        cadLabelSobrenome.setText("Sobrenome:");

        cadLabelNome.setText("Nome:");

        jLabel13.setText("/");

        jLabel14.setText("/");

        cadCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Médico", "Diretor", "Serviço Social", "Enfermeiro", "Técnico de Enfermagem", "Nutricionista", "Psicólogo", "Recepcionista", "Auxiliar de Enfermagem" }));
        cadCombo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cadComboItemStateChanged(evt);
            }
        });
        cadCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadComboActionPerformed(evt);
            }
        });

        jLabel15.setText("Telefone 2:");

        cadLabelNascimento.setText("Data de Nascimento:");

        cadLabel.setText("Tipo de Cadastro ");

        medLabelFormato1.setText("(DD/MM/AAAA)");

        cadComboEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Acre", "Alagoas", "Amapá", "Amazonas", "Bahia", "Ceará", "Distrito Federal", "Espirito Santo", "Goiás", "Maranhão", "Mato Grosso", "Mato Grosso do Sul", "Minas Gerais", "Pará", "Paraíba", "Paraná", "Pernambuco", "Piauí", "Rio de Janeiro", "Rio Grande do Norte", "Rio Grande do Sul", "Rondônia", "Roraima", "Santa Catarina", "São Paulo", "Sergipe", "Tocantins" }));
        cadComboEstado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadComboEstadoActionPerformed(evt);
            }
        });

        medLabelCPF1.setText("CPF:");

        jLabel17.setText("Cidade:");

        jLabel18.setText("Estado:");

        jLabel19.setText("Endereço:");

        cadLabelVariavel.setText("CRM:");

        cadLabelTipo.setText("Cadastro de Médico");

        medBotaoCadastrar1.setText("Cadastrar");
        medBotaoCadastrar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                medBotaoCadastrar1ActionPerformed(evt);
            }
        });

        medBotaoLimpar1.setText("Limpar");
        medBotaoLimpar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                medBotaoLimpar1ActionPerformed(evt);
            }
        });

        cadCampoTelefone2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadCampoTelefone2ActionPerformed(evt);
            }
        });

        jLabel1.setText("Nome de Usuário :");

        campoLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                campoLoginActionPerformed(evt);
            }
        });

        jLabel2.setText("Senha:");

        jLabel3.setText("Confirmar Senha:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator2)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cadLabelTipo)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cadLabelNome)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cadCampoNome)
                                .addGap(106, 106, 106))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cadLabelSobrenome)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cadCampoSobrenome))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(cadLabelNascimento)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cadCampoDia, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(medLabelCPF1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cadCampoCPF, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel14)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cadCampoMes, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(cadLabelVariavel))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(19, 19, 19)
                                        .addComponent(jLabel13)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cadCampoAno, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(medLabelFormato1))
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cadCampoVariable))))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel19)
                                .addGap(18, 18, 18)
                                .addComponent(cadCampoEndereco))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cadCampoDDD1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cadCampoTelefone1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel18)
                                .addGap(4, 4, 4)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cadCampoCidade)
                                    .addComponent(cadComboEstado, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(cadLabel)
                                        .addGap(3, 3, 3)
                                        .addComponent(cadCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel15)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cadCampoDDD2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cadCampoTelefone2, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel17))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addComponent(jLabel1)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(campoLogin))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addGap(162, 162, 162)
                                                .addComponent(medBotaoCadastrar1)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(medBotaoLimpar1))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoConfSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cadLabel)
                    .addComponent(cadCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addComponent(cadLabelTipo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cadLabelNome)
                    .addComponent(cadCampoNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cadLabelSobrenome)
                    .addComponent(cadCampoSobrenome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cadLabelNascimento)
                    .addComponent(cadCampoDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(cadCampoMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(cadCampoAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(medLabelFormato1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(medLabelCPF1)
                    .addComponent(cadCampoCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cadLabelVariavel)
                    .addComponent(cadCampoVariable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(cadCampoDDD1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cadCampoTelefone1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18)
                    .addComponent(cadComboEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(cadCampoDDD2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cadCampoTelefone2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17)
                    .addComponent(cadCampoCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(cadCampoEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(campoLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(campoSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(campoConfSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(medBotaoCadastrar1)
                    .addComponent(medBotaoLimpar1))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cadCampoTelefone1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadCampoTelefone1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cadCampoTelefone1ActionPerformed

    private void cadComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadComboActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cadComboActionPerformed

    private void cadComboEstadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadComboEstadoActionPerformed
        
    }//GEN-LAST:event_cadComboEstadoActionPerformed

    private void cadCampoTelefone2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadCampoTelefone2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cadCampoTelefone2ActionPerformed

    private void cadComboItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cadComboItemStateChanged
        
        StringBuilder sb = new StringBuilder("Cadastro de ");
        sb.append((String)cadCombo.getSelectedItem());
        cadLabelTipo.setText(sb.toString());
        
        cadCampoVariable.setEnabled(true);
        String tipo = (String)cadCombo.getSelectedItem();
        if(tipo.equals("Médico")) cadLabelVariavel.setText("CRM");
        else if(tipo.equals("Nutricionista")) cadLabelVariavel.setText("CRN");
        else if(tipo.equals("Psicólogo")) cadLabelVariavel.setText("CRP");
        else if(tipo.equals("Enfermeiro")) cadLabelVariavel.setText("COREN");
        else if(tipo.equals("Técnico de Enfermagem")) cadLabelVariavel.setText("COREN");
        else if(tipo.equals("Auxiliar de Enfermagem")) cadLabelVariavel.setText("COREN");
        else if(tipo.equals("Serviço Social")) cadLabelVariavel.setText("CRESS");
        else{
            cadLabelVariavel.setText("");
            cadCampoVariable.setEnabled(false);
        }
        
    }//GEN-LAST:event_cadComboItemStateChanged

    private void medBotaoCadastrar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_medBotaoCadastrar1ActionPerformed
        String nome = cadCampoNome.getText();
        String sobrenome = cadCampoSobrenome.getText();
        String dia = cadCampoDia.getText();
        String mes = cadCampoMes.getText();
        String ano = cadCampoAno.getText();
        String cpf = cadCampoCPF.getText();
        String ddd1 = cadCampoDDD1.getText();
        String tel1 = cadCampoTelefone1.getText();
        String ddd2 = cadCampoDDD2.getText();
        String tel2 = cadCampoTelefone2.getText();
        String cidade = cadCampoCidade.getText();
        String ender = cadCampoEndereco.getText();
        String estado = cadComboEstado.getSelectedItem().toString();
        String login = campoLogin.getText();
        String senha = campoSenha.getText();
        String confsenha = campoConfSenha.getText();
        String cod = cadCampoVariable.getText();
        
        //Testando se os campos obrigatórios estão preenchidos.
        if(!testString(nome, "O campo nome é obrigatório!")) return;
        if(!testString(sobrenome, "O campo sobrenome é obrigatório!")) return;
        if(!testString(dia, "O campo dia é obrigatório!")) return;
        if(!testString(mes, "O campo mês é obrigatório!")) return;
        if(!testString(ano, "O campo ano é obrigatório!")) return;
        if(!testString(cpf, "O campo cpf é obrigatório!")) return;
        if(!testString(ddd1, "O primeiro campo de DDD é obrigatório!")) return;
        if(!testString(tel1, "O primeiro campo de telefone é obrigatório!")) return;
        if(!testString(cidade, "O campo cidade é obrigatório!")) return;
        if(!testString(ender, "O campo endereço é obrigatório!")) return;
        if(!testString(login, "O campo Nome de Usuário é obrigatório!")) return;
        if(!testString(senha, "O campo Senha é obrigatório!")) return;
        if(!testString(confsenha, "O campo Confirmar Senha é obrigatório!")) return;
        if(cadCampoVariable.isEnabled()) if(!testString(cod, "O campo de código (CRM, CRP, CRESS, etc...) é obrigatório!")) return;
        
        //Fazendo a validação dos dados.        
        if(!Validador.validaNome(nome)){
            JOptionPane.showMessageDialog(null, "O nome digitado é inválido.", "Erro no cadastro", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(!Validador.validaNome(sobrenome)){
            JOptionPane.showMessageDialog(null, "O sobrenome digitado é inválido.", "Erro no cadastro", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(!Validador.validaCPF(cpf)){
            JOptionPane.showMessageDialog(null, "O cpf digitado é inválido.", "Erro no cadastro", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(!Validador.validaNome(cidade)){
            JOptionPane.showMessageDialog(null, "A cidade digitada é inválida.", "Erro no cadastro", JOptionPane.ERROR_MESSAGE);
            return;
        }
        String[] ddn = {dia, mes, ano};
        if(!Validador.validaDataNascimento(ddn)){
            JOptionPane.showMessageDialog(null, "A data de nascimento digitada é inválida.", "Erro no cadastro", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(!senha.equals(confsenha)){
            JOptionPane.showMessageDialog(null, "Falha na confirmação da senha.", "Erro no cadastro", JOptionPane.ERROR_MESSAGE);
            return;
        }
        
        StringBuilder sb = new StringBuilder();
        sb.append(dia);
        sb.append(mes);
        sb.append(ano);
        
        StringBuilder sb2 = new StringBuilder();
        sb2.append(ddd1);
        sb2.append(tel1);
        
        StringBuilder sb3 = new StringBuilder();
        sb3.append(ddd2);
        sb3.append(tel2);
        
        //Fazendo o cadastro
        String tipo = cadCombo.getSelectedItem().toString();
        if(tipo.equals("Médico")){
            Medico med = new Medico(nome, sobrenome, sb.toString(), cpf, login, senha,
                                    sb2.toString(), sb3.toString(), estado, cidade, ender, cod);
            MedicoJpaController mjpa = new MedicoJpaController();
            mjpa.create(med);
        }else if(tipo.equals("Diretor")){
            Diretor dir = new Diretor(nome, sobrenome, sb.toString(), cpf, login, senha,
                                      sb2.toString(), sb3.toString(), estado, cidade, ender);
            DiretorJpaController djpa = new DiretorJpaController();
            djpa.create(dir);
        }else if(tipo.equals("Serviço Social")){
            AssistenteSocial as = new AssistenteSocial(nome, sobrenome, sb.toString(), cpf, login, senha,
                                                       sb2.toString(), sb3.toString(), estado, cidade, ender, cod);
            AssistenteSocialJpaController asjpa = new AssistenteSocialJpaController();
            asjpa.create(as);
        }else if(tipo.equals("Enfermeiro")){
            Enfermeiro enf = new Enfermeiro(nome, sobrenome, sb.toString(), cpf, login, senha,
                                            sb2.toString(), sb3.toString(), estado, cidade, ender, cod);
            EnfermeiroJpaController ejpa = new EnfermeiroJpaController();
            ejpa.create(enf);
        }else if(tipo.equals("Técnico de Enfermagem")){
            TecnicoEnfermagem te = new TecnicoEnfermagem(nome, sobrenome, sb.toString(), cpf, login, senha,
                                                         sb2.toString(), sb3.toString(), estado, cidade, ender, cod);
            TecnicoEnfermagemJpaController tejpa = new TecnicoEnfermagemJpaController();
            tejpa.create(te);
        }else if(tipo.equals("Nutricionista")){
            Nutricionista nut = new Nutricionista(nome, sobrenome, sb.toString(), cpf, login, senha,
                                                  sb2.toString(), sb3.toString(), estado, cidade, ender, cod);
            NutricionistaJpaController njpa = new NutricionistaJpaController();
            njpa.create(nut);
        }else if(tipo.equals("Psicólogo")){
            Psicologo psi = new Psicologo(nome, sobrenome, sb.toString(), cpf, login, senha,
                                          sb2.toString(), sb3.toString(), estado, cidade, ender, cod);
            PsicologoJpaController pjpa = new PsicologoJpaController();
            pjpa.create(psi);
        }else if(tipo.equals("Auxiliar de Enfermagem")){
            AuxiliarEnfermagem psi = new AuxiliarEnfermagem(nome, sobrenome, sb.toString(), cpf, login, senha,
                                          sb2.toString(), sb3.toString(), estado, cidade, ender, cod);
            AuxiliarEnfermagemJpaController ajpa = new AuxiliarEnfermagemJpaController();
            ajpa.create(psi);
        }else if(tipo.equals("Recepcionista")){
            Recepcionista psi = new Recepcionista(nome, sobrenome, sb.toString(), cpf, login, senha,
                                          sb2.toString(), sb3.toString(), estado, cidade, ender);
            RecepcionistaJpaController rjpa = new RecepcionistaJpaController();
            rjpa.create(psi);
        }else{
            System.err.println("Opção inválida para cadastro de usuário.");
            return;
        }
        limparCampos();
    }//GEN-LAST:event_medBotaoCadastrar1ActionPerformed

    private void campoLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_campoLoginActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_campoLoginActionPerformed

    private void medBotaoLimpar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_medBotaoLimpar1ActionPerformed
        limparCampos();
    }//GEN-LAST:event_medBotaoLimpar1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JanelaCadastroFuncionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JanelaCadastroFuncionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JanelaCadastroFuncionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JanelaCadastroFuncionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                
                JanelaCadastroFuncionario.getInstance().setVisible(true);
            }
        });
    }
    
    boolean testString(String s, String msg){
        if(s == null || s.equals("")){
            JOptionPane.showMessageDialog(null, msg, "Erro no Cadastro", JOptionPane.ERROR_MESSAGE);
            return false;
        }
        else return true;
    }
    
    void limparCampos(){
        cadCampoAno.setText("");
        cadCampoCPF.setText("");
        cadCampoCidade.setText("");
        cadCampoDDD1.setText("");
        cadCampoDDD2.setText("");
        cadCampoDia.setText("");
        cadCampoEndereco.setText("");
        cadCampoMes.setText("");
        cadCampoNome.setText("");
        cadCampoSobrenome.setText("");
        cadCampoTelefone1.setText("");
        cadCampoTelefone2.setText("");
        cadCampoVariable.setText("");
        campoLogin.setText("");
        campoSenha.setText("");
        campoConfSenha.setText("");
        cadCombo.setSelectedItem("Médico");
        cadComboEstado.setSelectedItem("Acre");
    }
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField cadCampoAno;
    private javax.swing.JTextField cadCampoCPF;
    private javax.swing.JTextField cadCampoCidade;
    private javax.swing.JTextField cadCampoDDD1;
    private javax.swing.JTextField cadCampoDDD2;
    private javax.swing.JTextField cadCampoDia;
    private javax.swing.JTextField cadCampoEndereco;
    private javax.swing.JTextField cadCampoMes;
    private javax.swing.JTextField cadCampoNome;
    private javax.swing.JTextField cadCampoSobrenome;
    private javax.swing.JTextField cadCampoTelefone1;
    private javax.swing.JTextField cadCampoTelefone2;
    private javax.swing.JTextField cadCampoVariable;
    private javax.swing.JComboBox cadCombo;
    private javax.swing.JComboBox cadComboEstado;
    private javax.swing.JLabel cadLabel;
    private javax.swing.JLabel cadLabelNascimento;
    private javax.swing.JLabel cadLabelNome;
    private javax.swing.JLabel cadLabelSobrenome;
    private javax.swing.JLabel cadLabelTipo;
    private javax.swing.JLabel cadLabelVariavel;
    private javax.swing.JTextField campoConfSenha;
    private javax.swing.JTextField campoLogin;
    private javax.swing.JTextField campoSenha;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JButton medBotaoCadastrar1;
    private javax.swing.JButton medBotaoLimpar1;
    private javax.swing.JLabel medLabelCPF1;
    private javax.swing.JLabel medLabelFormato1;
    // End of variables declaration//GEN-END:variables
    private static JanelaCadastroFuncionario instance = null;
}
